// NodeRead.java

public class NodeStmtRead extends NodeStmt {

	java.util.Scanner input;
	Token id;
	NodeAssn assn;
	
	public NodeStmtRead(java.util.Scanner input, Token id) {
		this.input = input;
		this.id = id;
	}
	
	public double eval(Environment env) throws EvalException {
		String value = input.next();
	    // Treat it as an assignment.
	    NodeFactNum factNum = new NodeFactNum(value);
	    NodeTerm term = new NodeTerm(factNum, null, null);
	    NodeExpr expr = new NodeExpr(term, null, null);
	    this.assn = new NodeAssn(id.lex(), expr);
		return assn.eval(env);
	}
	
}
